<?php
/**
 *
 * @Author nikm $
 *
 * @Date 2011-01-04 $
 */

if(!defined('FROM_INDEX')) exit('Invalid request');

require ROOT_PATH.'include/lib/cache.func.php';
require ROOT_PATH.'include/lib/cookie.func.php';
require ROOT_PATH.'include/lib/session.func.php';
require ROOT_PATH.'include/sql/sql_functions.php';

class masterObj
{
	var $request = array();

	var $act = '';
	var $user = array();
	var $session = array();

	var $_is_messager = false;

	var $ajhAuthKey = '';

	function __construct($request)
	{
		load_setting('config_global');

		$this->request = $request;
		$this->act = $request['act'];

		$this->ajhAuthKey = md5(SEC_AUTHKEY.$_SERVER['HTTP_USER_AGENT'].'_IN_ADMIN_PANEL_'.date('Y-m-Y-m'));

		unset($ajhAuth, $_pwd, $_uid);
		if(($ajhAuth = cookie_get('ajhAuth')))
		{
			list($_pwd, $_uid) = explode("\t", authcode($ajhAuth, 'DECODE', $this->ajhAuthKey));
		}

		$user = get_user($_uid);

		if(!$ajhAuth || !$_pwd || ($_pwd != $user['password']) || ($_uid < 1) || ($_uid != $user['id']))
		{
			$this->messager('请登录');
		}

		$this->user = $user;

		$this->_checkUser();

		$this->updateSession();
	}
	
	function message($msg)
	{
		echo $msg;
		exit();
	}

	function updateSession()
	{
		$sid = cookie_get('sid');
		$session = session_get($sid);

		if(check_array($session))
		{
			$this->session = $session;
		}
		else
		{
			$this->session = session_init($sid);
		}

		session_update($this->session);
	}

	/**
	 *
	 * Check if user login & has permission
	 */
	function _checkUser()
	{
		return true;
	}
}